﻿using HuaCheng.Controller;
using HuaCheng.UserControls;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Timers;
using System.Windows.Forms;

namespace HuaCheng
{
    public partial class UcChannel : UserBase
    {
        public new UnitOrder uOrder;
        #region 初始化
        public UcChannel()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;//允许线程之间的操作
            //InitParam();//初始化单位参数
        }
        /// <summary>
        /// 从配置文件读取单位
        /// </summary>
        public override void InitParam()
        {
            uOrder = UnitOrderControl.GetUnit();
            this.lblVoltage.Text = "电压(" + uOrder.Voltage + ")";
            this.lblCurrent.Text = "电流(" + uOrder.Current + ")";
            this.lblCapacity.Text = "充电容量(" + uOrder.Capacity + ")";
            this.lblEnergy.Text = "充电能量(" + uOrder.Energy + ")";
        }
        public override Channels Channel
        {
            get { return channel; }
            set
            {
                channel = value;
                this.lblCHBig.Text = value.ChId;//柜号-映射通道号
                this.lblStepNumBig.Text = value.StepId.ToString();//工步序号
                this.lblIterNumBig.Text = value.IterId.ToString();//循环序号
                this.lblStepTimeBig.Text = value.StepTime;//时间
                this.lblVoltageBig.Text = value.Voltage == 0.0 ? "0.0000" : value.Voltage.ToString();//电压
                this.lblCurrentBig.Text = value.Current.ToString();//电流
                this.lblCapacityBig.Text = value.Capacity.ToString();//充电容量
                this.lblEnergyBig.Text = value.Energy.ToString();//充电能量
                if (value.pauseStat)
                {
                    this.lblRunStat.Text = "停止";
                    this.lblRunStat.ForeColor = Color.Blue;
                    this.lblVoltageBig.ForeColor = Color.Blue;
                }
             }
        }
        /// <summary>
        /// 设置完工步改变颜色
        /// </summary>
        /// <param name="c"></param>
        public override void SetUcColor(Color c)
        {
            this.BackColor = c;
        }
        /// <summary>
        /// 点击子控件时触发父控件点击事件，避免父控件点击事件被覆盖
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public new void lbl_MouseClick(object sender, MouseEventArgs e)
        {
            base.OnMouseClick(e);
        }
        /// <summary>
        /// 点击子控件时触发父控件点击事件，避免父控件点击事件被覆盖
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public new void lbl_MouseDown(object sender, MouseEventArgs e)
        {
            base.OnMouseDown(e);
        }
        #endregion


    }
}
